class UsersController < ApplicationController

  before_filter :find_user, :authorize

  def edit
  end

  def update
    if @user.update_attributes(params[:user])
      flash.now[:notice] = t("notifications.users.update.success")
    end

    respond_to do |format|
      format.html { render :edit }
      format.js { @user.reset_password_and_send_account_info! }
    end
  end

  private

  def find_user
    @user = current_user
  end

  def authorize
    redirect_to :root unless current_user.id == @user.id
  end
end
